package com.youcheng.config;

import com.youcheng.utils.ApiResponse;
import com.youcheng.utils.MyException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 全局异常处理
 */
@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(value = MyException.class)
    @ResponseBody
    public ApiResponse bizExceptionHandler(MyException e){
        return ApiResponse.error(e.getCode(),e.getMessage());
    }

}
